﻿@model WebApplication1.Models.LoginModel
@{
    ViewBag.Title = "登录";
}

<div class="row">
    <h3>用户登录</h3>
    @using (Html.BeginForm("Login", "Account", FormMethod.Post, new
    {
        @class = "m-t",
        @id = "form"
    }))
    {
        @Html.AntiForgeryToken()
        <div class="form-group">
            @Html.TextBoxFor(model => model.AccountName, new
       {
           @class = "form-control",
           @placeholder = "用户名",
           @required = "",
           @data_msg_required = "<i class='fa fa-times-circle'></i> 请输入用户名"
       })
        </div>
        <div class="form-group">
            @Html.PasswordFor(model => model.Password, new
       {
           @class = "form-control",
           @placeholder = "密码",
           @required = "",
           @data_msg_required = "<i class='fa fa-times-circle'></i> 请输入密码"
       })
        </div>
        <button type="button" class="btn btn-primary block full-width m-b" onclick="submitForm()">
            登 录
        </button>
    }
</div>

@section Scripts {
    <script>
        $(function () {

        });
        function submitForm() {
            $.ajax({
                type: "post",
                url: '/Default/Login',
                data: $('form').serialize(),
                dataType: "json",
                error: function (xhr, textStatus, errorThrown) {
                    alert("XHR=" + xhr + "\ntextStatus=" + textStatus + "\nerrorThrown=" + errorThrown);
                },
                success: function (result, textStatus) {
                    if (result.success) {
                        window.location.href = '/Default/Index';
                    }
                    else {
                        alert(result.msg+'/'+textStatus);
                    }
                }
            });
        }
    </script>
}




